﻿using System;
using AbpOne.ToolKits.Base.Enum;

namespace AbpOne.ToolKits.Base {
    /// <summary>
    /// 服务层响应实体(泛型)
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ServiceResult<T> : ServiceResult where T : class {
        /// <summary>
        /// 返回结果
        /// </summary>
        public T Result { get; set; }

        /// <summary>
        /// 响应成功
        /// </summary>
        /// <param name="result"></param>
        /// <param name="message"></param>
        public ServiceResult<T> Success(T result = null, string message = "") {
            Message = message;
            Code = ServiceResultCode.Succeed;
            Result = result;

            return this;
        }

        /// <summary>
        /// 响应失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public new ServiceResult<T> Fail(string message = "") {
            base.Fail(message);
            return this;
        }

        /// <summary>
        /// 响应失败
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public new ServiceResult<T> Fail(Exception exception) {
            base.Fail(exception);
            return this;
        }
    }
}